<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="h_top">
          <div class="bread_title">
            <span>新增知识</span>
          </div>
          <div class="save_button">
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-back" size="mini" @click="goBack">返回</el-button>
            </div>
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-document-checked" size="mini" @click="save">保存</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div>
      <el-row>
        <el-col :span="24">
          <el-form ref="form" :model="data" :inline="true" :rules="formRules">
            <el-row :gutter="10">
              <el-col :span="4">
                <el-form-item prop="coding">
                  <div>编号</div>
                  <el-input v-model="data.coding" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="name">
                  <div>名称</div>
                  <el-input v-model="data.name" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="parent_id">
                  <div>所属分类</div>
                  <el-input v-model="data.category" size="mini" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="format">
                  <div>附件类型</div>
                  <el-select v-model="data.format" size="mini">
                    <el-option v-for="(item, index) in knowledgeFormat" :key="index" :value="index" :label="item" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="eq_first_category_id">
                  <div>设备一级分类</div>
                  <v-select v-model="data.eq_first_category_id" action="equipmentCategoryList" :query="{level:0}" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="eq_category_id">
                  <div>设备终极分类</div>
                  <v-select v-model="data.eq_category_id" action="equipmentCategoryList" :disabled="!data.eq_first_category_id" :query="{parent_id:data.eq_first_category_id}" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="sort">
                  <div>排序</div>
                  <el-input v-model="data.sort" size="mini" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-tabs>
            <el-tab-pane label="描述">
              <el-row :gutter="10">
                <el-col :span="24">
                  <Tinymce id="content" v-model="data.content" />
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import API from '@/api/knowledge/knowledge'
import { knowledgeFormat } from '@/utils/options'
import Tinymce from '@/components/Tinymce/index'
import VSelect from '@/components/select'
export default {
  inject: ['addOne', 'goUrl'],
  components: {
    Tinymce,
    VSelect
  },
  data() {
    return {
      data: {
        coding: '',
        name: '',
        category: '',
        sort: '100'
      },
      knowledgeFormat,
      formRules: {
        coding: [
          {
            required: true,
            message: '请输入编号',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '请输入文档名称',
            trigger: 'blur'
          }
        ],
        format: [
          {
            required: true,
            message: '请选择附件类型',
            trigger: 'change'
          }
        ],
        sort: [
          {
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  watch: {},
  created() {
    this.data.category = this.$route.query.name
    this.data.category_id = this.$route.query.category
  },
  methods: {
    save() {
      const thisData = this.data
      const thisForm = this.$refs.form
      this.addOne(API, thisData, thisForm)
    },
    goBack() {
      this.goUrl('/knowledge/knowledge')
    }
  }
}
</script>

